import React, { Component } from 'react'
import {ListBox} from '../../components'
import UpdateMdPackagePage from './Update'
import { Modal } from 'antd';

export default class ListMdPackage extends Component {
    constructor(props) {
           super(props);
         this.state = {
               loading: false,
               visible: false,
           };

        //行操作列表
        this.rowOperation = [

        ];
        //header 操作列表
        this.headerOperation = [
            {
                handleName: 'add',
                showName: '新增',
                iconClass: 'plus'
            },{
                handleName: 'edit',
                showName: '修改',
                iconClass: 'edit'
            },{
                handleName: 'delete',
                showName: '删除',
                iconClass: 'delete'
            }
        ];

        //table列表展示列配置
        //showName、columnName 必有属性， columnWidth 可选，默认100, columnHidden: true 列隐藏
        this.tableColumn = {
            storageKey: 'ListMdPackageColumnConfig',
            data: [
                {
                    showName: 'id',
                    columnName: 'packageId',
                    columnHidden:true,
                    foreverHidden: true
                },
                {
                    showName: '包装代码',
                    columnName: 'packageCode'
                },{
                    showName: '包装描述',
                    columnName: 'packageDesc'
                },{
                    showName: '创建人',
                    columnName: 'createBy'
                },{
                    showName: '创建时间',
                    columnName: 'gmtCreate'
                },{
                    showName: '更新人',
                    columnName: 'lastModifiedBy'
                },{
                    showName: '更新时间',
                    columnName: 'gmtModified'
                }
            ]
        };

        this.searchComponentData = [
            {
                showName: '包装代码',
                name:'packageCode',
                type: 'input',
                url: null
            },{
                showName: '包装描述',
                name:'packageDesc',
                type: 'input',
                url: null
            },{
                name:'gmtCreate',
                type: 'date',
                maxName:'gmtCreateMax', //最大值， 选择小于时使用；选择范围时大值使用
                minName:'gmtCreateMin'  //最小值， 选择大于时使用；选择范围时小值使用
            },{
                name:'gmtModified',
                type: 'date',
                maxName:'gmtModifiedMax',
                minName:'gmtModifiedMin'
            }
        ];

       }

// 行操作
    rowHandles = (strHandles, rowObj) => {
        if(strHandles === 'edit'){
            this.editHandle(rowObj);
        }else if(strHandles === 'delete'){
            this.deleteHandle(rowObj);
        }else if(strHandles === 'add'){
            this.addHandle();
        }
    }

    addHandle = () => {
        this.refs.updatemdpackage.addHandle();
    }

    editHandle = (rowObj) => {
        if(rowObj.length == 0){
            Modal.error({
                title: '错误提示',
                content: '请选择一条数据',
            });
        }else if(rowObj.length > 1){
            Modal.error({
                title: '错误提示',
                content: '只能选择一条数据',
            });
        }else{
            this.refs.updatemdpackage.editHandle(rowObj[0].data);
        }
    }

    deleteHandle = (rowObj) => {
        if(rowObj.length == 0){
            Modal.error({
                title: '错误提示',
                content: '请选择一条数据',
            });
        }else if(rowObj.length > 1){
            Modal.error({
                title: '错误提示',
                content: '只能选择一条数据',
            });
        }else{
            this.refs.updatemdpackage.getFormData[1].disable = true;
            this.refs.updatemdpackage.deleteHandle(rowObj[0].data);
        }
    }

    //刷新列表
    refreshHandle = () => {
        this.refs.mdpackageList.refreshHandle();
    }
  render() {
      //formAlerSize和getFormData都是必传值
      let isHideLeft = this.props.isHideLeft;

    return (
      <div style={{height:'100%'}}>
          <ListBox
              ref = 'mdpackageList'
              isHideLeft={isHideLeft}
              title=" 包装管理"
              tableColumnData = {this.tableColumn}
              searchComponentData={this.searchComponentData}
              url = '/base/data/mdpackage/list'
              rowHandles = {this.rowHandles}
              rowOperation = {this.rowOperation}
              headerOperation = {this.headerOperation}
              isRowSingle = "true"
          />

          <UpdateMdPackagePage
              ref="updatemdpackage"
              refreshHandle = {this.refreshHandle}
          />

      </div>
    );
  }
}
